package com.edu.service.queryanswer.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.edu.entity.queryanswer.Query;
import com.edu.entity.queryanswer.Querypage;
import com.edu.entity.queryanswer.Querysc;
import com.edu.entity.shop.Collect;
import com.edu.entity.user.EduUser;
import com.edu.entity.user.SysUser;
import com.edu.mapper.queryanswer.QueryMapper;
import com.edu.service.queryanswer.QueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class QueryServiceImpl implements QueryService {
    private static Integer CURRENT_PAGE=1;
    private static Integer PAGE_SIZE=8;
    @Autowired
    private QueryMapper queryMapper;
    @Override
    public List<Query> findQueryByName(String querytitle,Integer page,Integer size) {
        if (page != null){
            CURRENT_PAGE=page;
        }
        if (size!=null){
            PAGE_SIZE=size;
        }
        return queryMapper.selectQuery("%"+querytitle+"%",(CURRENT_PAGE-1)*PAGE_SIZE,PAGE_SIZE);
    }
    @Override
    public void insertquery(Query query) {
        queryMapper.insertquery(query);
    }
    @Override
    public List<Query> queryList(Integer page,Integer size) {
        if (page != null){
            CURRENT_PAGE=page;
        }
        if (size!=null){
            PAGE_SIZE=size;
        }
        System.out.println(page+"ee");
        Querypage querypage=new Querypage((CURRENT_PAGE-1)*PAGE_SIZE,PAGE_SIZE);
        return queryMapper.queryList(querypage);
    }

    @Override
    public Query findById(Integer id) {

        return queryMapper.findById(id);
    }

    @Override
    public int gettotal(String queryname) {
        return queryMapper.gettotal(queryname);
    }

    @Override
    public int selecttotal(String querytitle) {
        return queryMapper.getselecttotal("%"+querytitle+"%");
    }

    @Override
    public List<Query> pageList() {
        return queryMapper.pageList();
    }

    @Override
    public List<Query> reslovequery(Integer page,Integer size) {
        if (page != null){
            CURRENT_PAGE=page;
        }
        if (size!=null){
            PAGE_SIZE=size;
        }
        System.out.println("gggg");
        return queryMapper.reslove((CURRENT_PAGE-1)*PAGE_SIZE,PAGE_SIZE);
    }
    @Override
    public EduUser findUserByPrin(String username) {
        return queryMapper.findUserByPrin(username);
    }

    @Override
    public void insertCollect(Querysc querysc) {
      queryMapper.insertCollect(querysc);
    }

    @Override
    public void broswerin(int id) {
        queryMapper.broswerin(id);
    }
}
